Use case: Starting the GFXTIM with absolute frame line timer ¶
This use case shows how to start the absolute line counter using the frame/line clock generator and handle line compare and overflow events.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
GFXTIM_HandleTypeDef hgfxtim;
hgfxtim.Instance = GFXTIM;
hgfxtim.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_ALC_COMPARE1_CB_ID,
USER_GFXTIM_ABSTIM_LineCmp1Callback);
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_ALC_OVERFLOW_CB_ID,
USER_GFXTIM_ABSTIM_LineCntOverFlowCallback);
/* Configure the GFXTIM clock generator */
GFXTIM_ClockGeneratorConfigTypeDef ClockGenConfig = {
.LCCHwReloadSrc = GFXTIM_LCC_HW_RELOAD_SRC_NONE;
.LCCReloadValue = 159999;
.LCCClockSrc = GFXTIM_LCC_CLK_SRC_SYSCLOCK;
.LineClockSrc = GFXTIM_LINE_CLK_SRC_LCC_UNDERFLOW;
.FCCHwReloadSrc = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCReloadValue = 0;
.FCCClockSrc = GFXTIM_FCC_CLK_SRC_DISABLE;
.FrameClockSrc = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
.LineClockCalib = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
&pClockGeneratorConfig);
/* Absolute line timer configuration */
GFXTIM_AbsoluteTimerConfigTypeDef pAbsoluteTimerConfig = {
.LineCounterValue = 0;
.LineCompare1Value = 1500;
.LineCompare2Value = 3000;
.FrameCounterValue = 0;
.FrameCompare1Value = 0;
.FrameOverflowInterrupt = DISABLE;
.FrameCompare1Interrupt = DISABLE;
/* optional: if interrupt is enabled */
.LineOverflowInterrupt = ENABLE;
.LineCompare1Interrupt = ENABLE;
.LineCompare2Interrupt = ENABLE;
};
HAL_GFXTIM_AbsoluteTimer_Config(&hgfxtim,
&pAbsoluteTimerConfig);
/* Start the absolute line counter */
HAL_GFXTIM_AbsoluteTimer_Start(&hgfxtim);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_AbsoluteTimer_ALCC1Callback(&hgfxtim);
USER_GFXTIM_AbsoluteTimer_ALCC2Callback(&hgfxtim);
USER_GFXTIM_AbsoluteTimer_ALCOFCallback(&hgfxtim);
/* Disable the absolute line counter */
HAL_GFXTIM_AbsoluteTimer_Stop(&hgfxtim);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
hal_gfxtim_handle_t hgfxtim;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_ABSTIM_RegisterLCmpCallback(&hgfxtim,
USER_GFXTIM_ABSTIM_LineCmpCallback);
HAL_GFXTIM_ABSTIM_RegisterLCntOverFlowCallback(&hgfxtim,
USER_GFXTIM_ABSTIM_LineCntOverFlowCallback);
/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_line_config_t p_line_config = {
.reload_src = HAL_GFXTIM_CLKGEN_LCNT_NO_RELOAD;
.reload_val = 159999;
.counter_src = HAL_GFXTIM_CLKGEN_LINE_COUNT_GFXTIMHCLK;
.clock_src = HAL_GFXTIM_CLKGEN_LINE_LCNT_UNDERFLOW;
};
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val = 0xFU;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_DISABLE;
.clock_src = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};
HAL_GFXTIM_CLKGEN_SetConfigLineFrameClock(&hgfxtim,
&p_frame_config,
&p_line_config);
/* Optional :Set the absolute line counter */
HAL_GFXTIM_ABSTIM_SetLineCounter(&hgfxtim, 0U);
/* Set the absolute line compare 1 value */
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COMP_1,
1500U);
/* Set the absolute line compare 2 value */
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COMP_2,
3000U);
/* Start the absolute line counter when interrupt is disabled */
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COUNTER,
HAL_GFXTIM_NONE_IT);
/* optional: if interrupt is enabled */
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COUNTER,
HAL_GFXTIM_ABSTIM_LINE_ALL_IT);
/* IRQHandler function */
HAL_GFXTIM_ABSTIM_LineIRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_ABSTIM_LCmpCallback(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COMP_1);
USER_GFXTIM_ABSTIM_LCmpCallback(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COMP_2);
USER_GFXTIM_ABSTIM_LCntOverFlowCallback(&hgfxtim);
/* optional */
/* Pause the absolute line counter */
HAL_GFXTIM_ABSTIM_Pause(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COUNTER);
/* Check that the absolute line counter is paused */
HAL_GFXTIM_ABSTIM_Resume(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COUNTER);
/* Disable the absolute line counter */
HAL_GFXTIM_ABSTIM_Stop(&hgfxtim,
HAL_GFXTIM_ABSTIM_LINE_COUNTER);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
Key changes ¶
HAL2 splits clock generator configuration into dedicated line and frame configuration structures.
HAL2 replaces the monolithic absolute timer configuration with unitary line counter and compare configuration APIs.

